name: Build and Deploy
on:
  pull_request:
    branches: [ "master", "develop", "release/**", "feature/**" ]
    types: [ opened, reopened, synchronize, closed ]

jobs:
  build-and-deploy:

    if: github.event.pull_request.state != 'closed' || github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
      id-token: write

    steps:
      - name: Print env
        run: |
          echo "$GITHUB_CONTEXT"

      - name: Checkout repository
        uses: actions/checkout@v3

      - uses: actions/setup-java@v3
        with:
          java-version: '21'
          distribution: 'oracle'

      - name: Build with Maven
        run: mvn --batch-mode --update-snapshots clean package -s config/mvn/settings.xml -P default,production